package com.turtle3d.user.visualizators;

import java.util.ArrayList;

import javax.media.j3d.Appearance;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Material;
import javax.vecmath.Color3f;

import com.turtle3d.formallanguage.VisualSymbol;
import com.turtle3d.formallanguage.symbol.Symbol;
import com.turtle3d.visualizator.MyPyramid;
import com.turtle3d.visualizator.VisualData;
import com.turtle3d.visualizator.VisualizatorAdapter;



public class Pyramid extends VisualizatorAdapter {

	/**
	 * @param args
	 */
	
	public BranchGroup visualize(VisualData visualData){
		BranchGroup branchGroup = new BranchGroup();
		
		ArrayList<VisualSymbol> visualSequence = visualData.getVisualSequence();
		
		for(int i=0;i<visualSequence.size();i++){
			
			VisualSymbol visualSymbol = visualSequence.get(i);
			
			if(!visualSymbol.getSymbol().equals(new Symbol("B")))
				continue;
			
			int depth = visualSymbol.getDepth();															
			Float a = visualSymbol.getSymbol().getParameter("distance");
			float normalizedDepth = depth/(visualData.getMaximalDepthReached()*1f);			
																																															
			//MyCone myCone = new MyCone(h,r,0, 4, true);
			MyPyramid myCone = new MyPyramid(a);
			
			myCone.setName("Grammar_"+depth);

			Appearance appearance = new Appearance();
			Material m = new Material();					
			m.setDiffuseColor(new Color3f(1f, normalizedDepth, 0f));
			appearance.setMaterial(m);
			myCone.setAppearance(appearance);	
						
			
			branchGroup.addChild(createTransformGroup(visualSymbol.getTransform(), myCone));
			
		}					
		
		return branchGroup;
	}

}
